package cn.edu.scau.cmi.luoxintai.client;
import cn.edu.scau.cmi.luoxintai.SingletonProgramming.Chairman;
import javafx.application.Application;
import javafx.geometry.HPos;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
public class SingletonClient extends Application{
	private TextField tfChairman = new TextField();
	private static Label createResult= new Label();
	private Button btCreate	= new Button("Create!");
	
	
	public void start(Stage primaryStage) {
		//Creat UI
		GridPane gridPane = new GridPane();
		gridPane.setHgap(30);
		gridPane.setVgap(20);
		gridPane.add(new Label("Chairman's name: "), 0,0);
		gridPane.add(tfChairman, 1, 0);
		gridPane.add(btCreate, 1, 5);
		gridPane.add(createResult,1,1);
		//Set properties for UI
		gridPane.setAlignment(Pos.CENTER);
		GridPane.setHalignment(btCreate, HPos.RIGHT);
	
		//process events
		btCreate.setOnAction(e -> {
			int i = 1;
			String n = tfChairman.getText();
			Chairman obj = Chairman.getInstance(n);
			createResult.setText("Chairman's name:"+obj.getName());
			Label createResult= new Label();
			gridPane.add(createResult,1,i);
			createResult.setText("Chairman's name:"+obj.getName());
			
		});
				

		//Create a scene and place it in the stage
		Scene scene = new Scene(gridPane,400,250);
		primaryStage.setTitle("Create your Chairman");
		primaryStage.setScene(scene);
		primaryStage.show();
	}
/*	
	private  void createChairman() {
		String n = tfChairman.getText();
		Chairman obj = Chairman.getInstance(n);
		createResult.setText("Chairman's name:"+obj.getName());
//		Label resultC = new Label("Chairman's name:"+obj.getName());
		Label createResult2= new Label();
		gridPane.add(createResult2,2,1);
		createResult2.setText("@@");

	}
*/
		
	public static void main(String[] args) {
		Application.launch(args);
	}
	}
